// pages/gaoxueya/gaoxueya.js
const app = getApp()
import { addHighBlood, getPatuser } from '../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    form: {
      username: "",
      sex: "",
      age: "",
      height: "",
      weight: "",
      education: "",
      occupation: "",
      smoke_day: "",
      smoke_year: "",
      drink: "",
      sleeping_name: "",
      sleeping_time: "",
      sleeping_measure: "",
      high_blood: "",
      blood_name: "",
      is_law: "",
      artery: "",
      artery_thickness: "",
      sclerosis_plaques: "",
      blood_time_moring: "",
      fenji: "",
      case_year: "",
      is_chuzhen: "",
      blood_time_night: "",
      EGFR: "",
      creatinine: "",
      cholesterol: "",
      triglyceride: "",
      medical_history: "",
      LDL: "",
      homocysteine: "",
      diabetes_classification: "",
      sugar: "",
      saccharify: "",
      siesta: "",
      siesta_time: "",
      siesta_week: "",
      coffee:"",
      sport_name: "",
      sport_time: "",
      sport_week: "",
      sport_quantum: [
        {
          name: '上午',
          val: 1
        },
        {
          name: '下午',
          val: 1
        },
        {
          name: '晚饭后',
          val: 1
        }
      ],
      CPC: "",
      last_night_time: "",
      today_wake_time: "",
      wake_minutes: "",
      menopause: "",
      first_low_blood: "",
      first_high_blood: "",
      tow_low_blood: "",
      tow_high_blood: ""
    },
    list: [],
    info: {},
    hasUserInfo: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this = this
    if (app.globalData.userInfo) {
      getPatuser({ openid: app.globalData.openid }).then(res => {
        _this.setData({
          list: res.data.quesurvey_list,
          info: res.data.user_info,
          'form.username': res.data.user_info.realname,
          'form.sex': res.data.user_info.gender == 1 ? '男' : '女',
          'form.age': res.data.user_info.age
        })
      })
      this.setData({
        hasUserInfo: true
      })
    }
  },
  // 1
  onChange1(event) {
    this.setData({
      'form.username': event.detail
    })
  },
  // 2
  onChange2(event) {
    this.setData({
      'form.sex': event.target.dataset.text
    })
  },
  // 3
  onChange3(event) {
    this.setData({
      'form.age': event.detail
    })
  },
  // 4
  onChange4(event) {
    this.setData({
      'form.height': event.detail
    })
  },
  // 5
  onChange5(event) {
    this.setData({
      'form.weight': event.detail
    })
  },

  // 6
  onChange6(event) {
    this.setData({
      'form.education': event.target.dataset.text
    })
  },

  // 7
  onChange7(event) {
    this.setData({
      'form.occupation': event.target.dataset.text
    })
  },

  // 8
  onChange8(event) {
    this.setData({
      'form.smoke_day': event.detail
    })
  },

  // 9
  onChange9(event) {
    this.setData({
      'form.smoke_year': event.detail
    })
  },

  // 10
  onChange10(event) {
    this.setData({
      'form.sleeping_name': event.detail
    })
  },

  // 11
  onChange11(event) {
    this.setData({
      'form.sleeping_time': event.detail
    })
  },

  // 12
  onChange12(event) {
    this.setData({
      'form.sleeping_measure': event.detail
    })
  },

  // 13
  onChange13(event) {
    this.setData({
      'form.high_blood': event.target.dataset.text
    })
  },

  // 14
  onChange14(event) {
    this.setData({
      'form.blood_name': event.detail
    })
  },

  // 15
  onChange15(event) {
    this.setData({
      'form.is_law': event.target.dataset.text
    })
  },

  // 16
  onChange16(event) {
    this.setData({
      'form.artery': event.target.dataset.text
    })
  },

  // 17
  onChange17(event) {
    this.setData({
      'form.artery_thickness': event.detail
    })
  }, 

  // 18
  onChange18(event) {
    this.setData({
      'form.sclerosis_plaques': event.detail
    })
  }, 

  // 19
  onChange19(event) {
    this.setData({
      'form.EGFR': event.detail
    })
  },

  // 20
  onChange20(event) {
    this.setData({
      'form.creatinine': event.detail
    })
  },

  // 21
  onChange21(event) {
    this.setData({
      'form.cholesterol': event.detail
    })
  },

  // 22
  onChange22(event) {
    this.setData({
      'form.triglyceride': event.detail
    })
  },

  // 23
  onChange23(event) {
    this.setData({
      'form.medical_history': event.detail
    })
  },

  // 24
  onChange24(event) {
    this.setData({
      'form.LDL': event.detail
    })
  },

  // 25
  onChange25(event) {
    this.setData({
      'form.homocysteine': event.detail
    })
  },

  // 26
  onChange26(event) {
    this.setData({
      'form.diabetes_classification': event.detail
    })
  },

  // 27
  onChange27(event) {
    this.setData({
      'form.sugar': event.detail
    })
  },

  // 28
  onChange28(event) {
    this.setData({
      'form.saccharify': event.detail
    })
  },

  // 29
  onChange29(event) {
    this.setData({
      'form.siesta': event.target.dataset.text
    })
  },

  // 30
  onChange30(event) {
    this.setData({
      'form.siesta_time': event.detail
    })
  },

  // 31
  onChange31(event) {
    this.setData({
      'form.siesta_week': event.detail
    })
  },

  // 32
  onChange32(event) {
    this.setData({
      'form.coffee': event.target.dataset.text
    })
  },
  // 33
  onChange33(event) {
    this.setData({
      'form.sport_name': event.detail
    })
  },
  // 34
  onChange34(event) {
    this.setData({
      'form.sport_time': event.detail
    })
  },

  // 35
  onChange35(event) {
    this.setData({
      'form.sport_week': event.detail
    })
  },

  // 36
  onChange36(e) {
    let _this = this
    let num = e.target.dataset.text
    if (this.data.form.sport_quantum[num].val == 1) {
      this.data.form.sport_quantum[num].val = 2
    } else {
      this.data.form.sport_quantum[num].val = 1
    }
    this.setData({
      'form.sport_quantum': _this.data.form.sport_quantum
    })
  },
  // 37
  onChange37(event) {
    this.setData({
      'form.CPC': event.detail
    })
  },
  // 38
  onChange38(event) {
    this.setData({
      'form.last_night_time': event.detail
    })
  },
  // 39
  onChange39(event) {
    this.setData({
      'form.today_wake_time': event.detail
    })
  },
  // 40
  onChange40(event) {
    this.setData({
      'form.wake_minutes': event.detail
    })
  },
  // 41
  onChange41(event) {
    this.setData({
      'form.menopause': event.target.dataset.text
    })
  },
  // 42
  onChange42(event) {
    this.setData({
      'form.drink': event.target.dataset.text
    })
  },
  // 43
  onChange43(event) {
    this.setData({
      'form.blood_time_moring': event.detail
    })
  },
  // 44
  onChange44(event) {
    this.setData({
      'form.blood_time_night': event.detail
    })
  },
  // 45
  onChange45(event) {
    this.setData({
      'form.is_chuzhen': event.target.dataset.text
    })
  },
  // 46
  onChange46(event) {
    this.setData({
      'form.fenji': event.detail
    })
  },
  // 47
  onChange47(event) {
    this.setData({
      'form.case_year': event.detail
    })
  },
  // 48
  onChange48(event) {
    this.setData({
      'form.first_low_blood': event.detail
    })
  },
  // 49
  onChange49(event) {
    this.setData({
      'form.first_high_blood': event.detail
    })
  },
  // 50
  onChange50(event) {
    this.setData({
      'form.tow_low_blood': event.detail
    })
  },
  // 51
  onChange51(event) {
    this.setData({
      'form.tow_high_blood': event.detail
    })
  },
  // 提交
  subClick () {
    let _this = this
    if (_this.data.form.username == '') {
      wx.showToast({
        title: '姓名不能为空！',
        icon: 'none',
        duration: 1500
      })
      return false;
    }
    _this.data.form.openid = app.globalData.openid
    addHighBlood(_this.data.form).then(res => {
      if (res.code == 200) {
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 1500
        })
        setTimeout(() => {
          wx.navigateBack({
            delta: 1
          })
        }, 1500)
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})